package com.zc.zby.basicframedemo.viewholder;

import android.support.annotation.NonNull;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.SparseArray;
import android.view.View;
import android.widget.TextView;

import com.jude.easyrecyclerview.EasyRecyclerView;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.zc.zby.basicframedemo.R;
import com.zc.zby.basicframedemo.adapter.CellAdapter;
import com.zc.zby.basicframedemo.model.CellModel;
import com.zc.zby.basicframedemo.model.TableModel;
import com.zc.zby.basicframedemo.weight.FullyLinearLayoutManager;

import java.util.ArrayList;

public class TableViewHolder extends BaseViewHolder<TableModel> {

    private final EasyRecyclerView mHRecyclerView;
    private final TextView mTvCell;

    public TableViewHolder(View view) {
        super(view);
        mHRecyclerView = $(R.id.HRecyclerView);
        mHRecyclerView.setLayoutManager(new FullyLinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false));
        mTvCell = $(R.id.cell_title);
    }

    @Override
    public void setData(TableModel data) {
        super.setData(data);
        mTvCell.setText("标题 " + getAdapterPosition());
        ArrayList<CellModel> cellModels = new ArrayList<>();
        cellModels.add(new CellModel());
        cellModels.add(new CellModel());
        cellModels.add(new CellModel());
        cellModels.add(new CellModel());
        CellAdapter cellAdapter = new CellAdapter(getContext());
        mHRecyclerView.setAdapter(cellAdapter);
        cellAdapter.addAll(cellModels);

        mHRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
            }

            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                mHRecyclerView.scrollTo(dx, dy);
            }
        });
    }

    private void onUIScrollChanged() {

    }
}
